function PageBackendSources(user, sd, options) {
  this._user = user;
  this._sd = sd;
  this._options = (options) ? options : null;
  
  this._gui = { content: document.getElementById('table2'),
                sourceNew: document.getElementById('img1')
              };
  
  this._createElements();
};

PageBackendSources.prototype._createElements = function() {
  var _self = this;
  
  this._gui.sourceNew.onclick = function() { location.href = '?p=pageasst&t=pagebackendsource&m1=a4&m2=b4';
                                           };
  
  this._loadData();
};

PageBackendSources.prototype._loadData = function() {
  var tr, td;
  tr = this._gui.content.insertRow(-1);
  td = tr.insertCell(-1);
  td.appendChild(DOMUtils.getLoadingImage());
  
  this._sources = null;
  this._retrieveSources();
};

PageBackendSources.prototype._verifyData = function() {
  if (this._sources) {
    this._updateElements();
  }
};

PageBackendSources.prototype._retrieveSources = function() {
  var _self = this;
  new RequestUtils()._read('source', null, null, null, null, null, null, function(result, params) { _self._sources = result.data;
                                                                                                    _self._verifyData.call(_self);
                                                                                                  }, null);
};

PageBackendSources.prototype._updateElements = function() {
  var _self = this, unique = new Date().getTime();
  
  DOMUtils.removeTableRows(this._gui.content, 1);
  
  tr = this._gui.content.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.height = '10px'; 
   
  if (this._sources.length == 0) {
    tr = this._gui.content.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 3;
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('Empty'));
  }
  
  for(var i = 0, il = this._sources.length; i < il; i++) {
    var source = this._sources[i];
    
    tr = this._gui.content.insertRow(-1);
    new GtrSource(i + '_' + unique, tr, source);
    
    var gui = { name: document.getElementById('link' + i + '_' + unique + '1'),
                btnDel: document.getElementById('button' + i + '_' + unique + '1')
              }
              
    gui.name._source = source;
    gui.name.onclick = function() { location.href = '?p=pageasst&t=pagebackendsource&m1=a4&m2=b4&opt=' + MiscUtils.encode(JSON.stringify({ sid: this._source.id }));
                                    return false;
                                  };
  
    gui.btnDel._source = source;
    gui.btnDel.onclick = function() { new RequestUtils()._write('source', [], [this._source], function() { _self._createElements.call(_self); }, null);
                                      return false;
                                    };
  }
};

